// pages/footprint/footprint.js\

var app = getApp();
// 语言
var util = require('../../utils/util.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    lists:[],
    isManage:false,
    isAllSelect:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getLists()
  },
  getLists(){
    var that = this;
    let customer_id = wx.getStorageSync('customer_id')
    wx.request({
      url: app.globalData.urls + '/order/footprint',
      header: app.getPostRequestHeader(),
      method: 'POST',
      data: {
        customer_id:customer_id.customer_id
      },
      success: function (res) {
        let code = res.data.code,data = res.data.data;
        console.log("获取足迹",code,data)
        if(code==200){
          that.setData({
            lists: data
          })
        }
      }
    })
  },
  gotodetail(e){
    wx.navigateTo({
      url: "/pages/goods-detail/goods-detail?id=" + e.currentTarget.dataset.item.product_id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  manage(){
    this.setData({
      isManage: !this.data.isManage
    })
  },
  singleSelect(e){
    let data = e.currentTarget.dataset;
    data.item.checked = !data.item.checked;
    this.setData({
      ["lists["+data.index+"]"]:data.item
    })
  },
  allSelect(){
    let datas = this.data.lists.map(val => {
      val.checked = this.data.isAllSelect
      return val;
    })
    this.setData({
      isAllSelect: !this.data.isAllSelect,
      lists: datas
    })
  },
  deleteGoods(){
    let params = this.data.lists.filter(val => val.checked).map(val => Number(val.id));
    var that = this, header = app.getPostRequestHeader();
    wx.request({
      url: app.globalData.urls + '/order/delete-footprint',
      header: {
        "access-token": header['access-token'],
        "fecshop-currency": header['access-token'],
        "fecshop-lang": "zh"
      },
      method: 'POST',
      data: {
        id: params
      },
      success: function (res) {
        let code = res.data.code;//, data = res.data.data
        if (code == 200) {
          that.getLists();
          that.setData({
            isAllSelect:false,
            isManage:false,
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})